/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				PlayerExistsCondition
 
Function						: 				Provides a class for whether a player 
 												exists condition
****************************************************************************/
package planninglanguage.conditions;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;


public class PlayerExistsCondition extends Condition {

	int m_playerID;
	
	public PlayerExistsCondition(int a_playerID)
	{
		m_playerID = a_playerID;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n + "Player Id is:" + m_playerID;
		return n;
	}
	
	public boolean compare(PlayerExistsCondition c)
	{
		if(m_playerID==c.m_playerID)
			return true;
		else
			return false;
	}
	
	public boolean test(WargusGameState a_gameState)
	{
		if (a_gameState.getPlayer(m_playerID)!=null) return true;

		return false;	
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			w.tag("player-id", m_playerID);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new PlayerExistsCondition(Integer.parseInt(e.getChildText("player-id")));
	}
}